//常用正则表达式
REGEXP_EMAIL = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
REGEXP_URL = /[a-zA-z]+:\/\/[^\s]*/;
REGEXP_ZIPCODE = /[1-9]\d{5}(?!\d)/;
REGEXP_INTEGER = /^[1-9]\d*$/;
REGEXP_FLOAT = /(^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$)|(^[1-9]\d*$)/;
function fieldValidateByRegexp(field,patrn){
	if(field.value.length < 1){
		return true;
	}
	if(!patrn.exec(field.value)){
   		alertRegMessage(field);
   		return false;
    }
    return true;
}

function alertRegMessage(field){
	var message = "格式不正确！";
	if(document.getElementById(field.name + SURFIX)){
   		alert(document.getElementById(field.name + SURFIX).innerHTML + message);
   	} else{
   		alert(message + field.name);
   	}
}

var SURFIX = "_TEXT"; 
function formIsNotEmpty(form){
  if(null == form){
  	return false;
  }
  
  //验证
  var elements = form.elements;
  for(i = 0;i < elements.length;i++){
    if("text" == elements[i].type || "password" == elements[i].type){
      if(elements[i].value.length < 1){
   		alertMessage(elements[i]);
   		return false;
      }
    }
	
    if("SELECT" ==  elements[i].tagName){
      if(elements[i].value == ""){
        alertMessage(elements[i]);
        return false;
      }
    }
  }
  return true;
}

function fieldIsNotEmpty(field){
	if(field.value.length < 1){
   		alertMessage(field);
   		return false;
      }
     return true;
}

function NumFieldLength(field,minLength){
	if(!field || null == field){
		return false;
	}
	if(field.value.length < minLength){
		alert(document.getElementById(field.name + SURFIX).innerHTML + "不能小于" + minLength + "位");
		return false;
	}
	return true;
}

function alertMessage(field){
	var message = "请输入";
	if("SELECT" ==  field.tagName){
		message = "请选择";
	}else if("FILE" ==  field.tagName){
		alert("请选择上传的文件！");
		return;
	}
	if(document.getElementById(field.name + SURFIX)){
   			alert(message + document.getElementById(field.name + SURFIX).innerHTML);
   		} else{
   			alert(message + field.name);
   		}
}

function campare2FieldsLessOrEqualThan(lessField,moreField){
	var result = parseFloat(lessField.value) <= parseFloat(moreField.value);
	if(!result){
		if(document.getElementById(lessField.name + SURFIX) && document.getElementById(moreField.name + SURFIX)){
   			alert(document.getElementById(lessField.name + SURFIX).innerHTML + "不能大于" + document.getElementById(moreField.name + SURFIX).innerHTML);
   		} else{
   			alert(document.getElementById(lessField.name).innerHTML + "不能大于" + document.getElementById(moreField.name).innerHTML);
   		}
	}
	return result;
}

function chksize(strFileName){
	if(strFileName.length < 1){
		return true;
	}
    var maxsize = 512*1024;    //定义允许文件的大小，单位KB，请根据需要自行修改！
    var objStream = new ActiveXObject("Scripting.FileSystemObject");   ;
	var file = objStream.GetFile(strFileName);
	
    if(file.size > maxsize){
        alert("文件大小不能超过512KB！");
        return false;
    }
    return true;
}
